<?php
//Retrieve bugID to query update on
$bugToUpdate = $_POST['bugID'];
//database connection
require_once('database2.php');
//construct inner join with three tables (to display actual names and project)
$query = 	"SELECT b.bugID,b.Priority,b.Description,b.Status, Assignee, Owner, e1.Name AS EName, e1.Email AS EEmail, e1.Phone AS EPhone, e2.Name AS OName, e2.Email AS OEmail, e2.Phone AS OPhone, p.projectName AS PName,b.DateAssigned,b.DateClosed
				FROM BugMaster b
					INNER JOIN EmployeeMaster e1
						ON b.Assignee = e1.employeeID
					INNER JOIN EmployeeMaster e2
						ON b.Owner = e2.employeeID
					INNER JOIN ProjectMaster p
						ON b.projectID = p.projectID
						WHERE b.bugID='$bugToUpdate'";	
		
//construct query for comments related to bugID		
$query2 = "SELECT comID, bugID, e3.Name AS SName, Text, date
			FROM CommentMaster c
				INNER JOIN EmployeeMaster e3
				ON c.employeeID = e3.employeeID
			WHERE bugID = '$bugToUpdate'
			ORDER BY date";
//Submit both queries to database						
$bugchanges = $db->query($query);		
$comchanges = $db->query($query2);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Bugsby Tracking</title>
<link href="stylesheets/group1Site.css" rel="stylesheet" type="text/css">
<link rel="icon" href="graphics/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="graphics/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="scripts/jquery_datepicker/ui.all.css" type="text/css" media="screen" />
<script src="scripts/jquery-1.7.1.js"></script>
<script src="scripts/imageSwap.js"></script>

</head>

<body>
<div id="wrapper">
<div id="banner"> <img src="graphics/banner1.png" height="90" width="730" alt="bugsby logo"> </div>
<div id="leftcolumn">
  <div id="nav">
    <ul>
      <li><a href="index.html"><img src="graphics/home.ico" border=0 height="36" width="36" alt="home icon">&nbsp;Home</a></li>
      <li><a href="buglist.php"><img src="graphics/Spider.ico" border=0 height="36" width="36" alt="bug list icon">&nbsp;Bug List</a></li>
      <li><a href="buginfo.html"><img src="graphics/info.png" border=0 height="36" width="36" alt="Info">&nbsp;Info</a></li>
      <li><a href="bugmail.html"><img src="graphics/Gmail.png" border=0 height="36" width="36" alt="feedback icon">&nbsp;Contact</a></li>
    </ul>
  </div>
  <!-- End Nav id --> 
</div>
<!-- End leftcolumn -->

<div id="content">
  <h1>Bugsby - Bug To Update</h1>
  <p class="standardText">Below is the bug you selected for Update:</p>
 <form id="updateBug" action="update_bug.php" method="post">

  <table border="1">
    <?php foreach ($bugchanges as $bugchange) : ?>
    
    <tr>
    	<td> Bug to Update: </td>
        <td><?php echo $bugchange['bugID']; ?></td> 
        <input type="hidden" name="bugToUpdate" id="bugToUpdate" value="<?php echo $bugchange['bugID']; ?>" />

    </tr>
    <tr>
    <td> Current Priority: </td>
      <td><?php echo $bugchange['Priority']; ?></td>
	  <input type="hidden" name="oldPriority" id="oldPriority" value="<?php echo $bugchange['Priority']; ?>" />

       <td><label class="inputLabel">New Priority: </label></td>
      <td>
        
        <select name="updatePri">
          <option value="0"> Choose New Priority</option>
          <option value="1">1 - Must be Fixed</option>
          <option value="2">2 - Highly Desirable</option>
          <option value="3">3 - Nice to Have</option>
          <option value="4">4 - Low Priority</option>
        </select>
      </td>
    </tr>
      <tr>
    <td> Current Status: </td>
      <td><?php echo $bugchange['Status']; ?></td>
	  <input type="hidden" name="oldStatus" id="oldStatus" value="<?php echo $bugchange['Status']; ?>" />
       <td><label class="inputLabel">New Status: </label></td>
      <td>
        
        <select name="updateStatus">
          <option value="0"> Choose New Status</option>
          <option value="1">1 - New</option>
          <option value="2">2 - Open</option>
          <option value="3">3 - Test</option>
          <option value="4">4 - Rejected</option>
          <option value="5">5 - Closed</option>
        </select></td>
    </tr>
	
	<tr>
      <td> Current Due Date: </td>
      <td><?php echo $bugchange['DateClosed']; ?></td>
       <td><label class="inputLabel">New End Date (YYYY-MM-DD): </label></td>
      <td>
        <input type="text" name="updateDateClosed" id="updateDateClosed" value="<?php echo $bugchange['DateClosed']; ?>" />
      </td>
     </tr>
	 
	 <tr>
      <td> Current Assignee: </td>
      <td><?php echo $bugchange['EName']; ?></td>
	  <input type="hidden" name="oldAssignee" id="oldAssignee" value="<?php echo $bugchange['Assignee']; ?>" />
      <td><label class="inputLabel">New Developer Assigned: </label></td>
      <td>
        
        <select name="updateAssignee">
          <option value="0"> Choose Assignee</option>
          <option value="1">Brian M.</option>
          <option value="2">Venkata</option>
          <option value="3">Donnie</option>
          <option value="4">Pete S.</option>
          <option value="5">Frank</option>
        </select></td>
    </tr>
	
	<tr>
      <td> Current Project Manager: </td>
      <td><?php echo $bugchange['OName']; ?></td>
	  <input type="hidden" name="oldOwner" id="oldOwner" value="<?php echo $bugchange['Owner']; ?>" />
      <td><label class="inputLabel">New PM Assigned: </label></td>
      <td>
        
        <select name="updateOwner">
          <option value="0"> Choose PM</option>
          <option value="1">Brian M.</option>
          <option value="2">Venkata</option>
          <option value="3">Donnie</option>
          <option value="4">Pete S.</option>
          <option value="5">Frank</option>
        </select></td>
    </tr>
    
    <tr>
    	<td></td>
        <td></td>
    	<td>Submit Comment?</td>
        <td><input type="radio" name="inputComment" value="1" checked="checked">No Comment<br>
        <input type="radio" name="inputComment" value="2">Leave Comment<br>
        </td>
    
    </tr>
    
    <tr>
    	<td></td>
        <td></td>
        <td>Comment Text:</td>
        <td><textarea name="comments" id="commentSubmit" rows="6" cols="40"></textarea>
        </td>
    </tr>
    
      <tr>
    	<td></td>
        <td></td>
		<td><label class="inputLabel">Comment Submitter: </label></td>
      	<td>
        <select name="commentSubmitter">
          <option value="1">Brian M.</option>
          <option value="2">Venkata</option>
          <option value="3">Donnie</option>
          <option value="4">Pete S.</option>
          <option value="5">Frank</option>
        </select>
        </td>
      </tr>
      
      <tr>
      	<td></td>
      	<td></td>
       	<td><label class="inputLabel">Comment Date (YYYY-MM-DD): </label></td>
      	<td>
        <input type="text" name="commentDate" id="commentDate"/>
      	</td>
     </tr>
    <?php endforeach; ?>
   
  </table>
  <br />
  <table>
    <tr>
      <td><form action="update_bug.php" method="post" >
          <input type="image" SRC="graphics/gear.ico" width="48" height="48" ALT="Update Bug!" />
        </form>
      </td>
      <td>&nbsp;
        &nbsp; </td>
      <td><form action="buglist.php" method="post" >
          <input type="image" SRC="graphics/Spider.ico" width="48" height="48" ALT="Add Bug!" />
        </form>
      <td>
    </tr>
    <tr>
      <td><p>Confirm Update</p></td>
      <td>&nbsp;
        &nbsp; </td>
      <td><p>Return to Bug List</p></td>
    </tr>
  </table>
</div>
<hr>
<p>&nbsp;</p>
<div id="navGraphics">
<h2>Click on a Graphic to Choose an Option:</h2>
<table width="800" border="0">
  <tr>
    <td><a href="index.html"><img src="graphics/home.png" border=0 height="128" width="128" alt="homepage icon" rel="graphics/homeRed.png" class="rollover" /></a></td>
    <td><a href="buginfo.html"><img src="graphics/info.png" border=0 height="128" width="128" alt="information icon" rel="graphics/infoRed.png" class="rollover" /></a></td>
    <td><a href="bugmail.html"><img src="graphics/Gmail.png" border=0 height="128" width="128" alt="send email icon" rel="graphics/GmailRed.png" class="rollover" /></a></td>
  </tr>
  <tr>
    <td class="standardText">Bugsby Home</td>
    <td class="standardText">Information</td>
    <td class="standardText">Contact</td>
  </tr>
</table>
<table>
</div>
<p>&nbsp;</p>
<div id="footer"> Site Content: <a href="mailto:cs633group1@gmail.com">CS633 Group 1</a> </div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>
<script type="text/javascript">
        $(document).ready(function(){
		$("#commentDate").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: 'scripts/jquery_datepicker/images/icon_cal.png', dateFormat: 'yy-mm-dd'});
        });
</script>
<script type="text/javascript">
        $(document).ready(function(){
		$("#updateDateClosed").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: 'scripts/jquery_datepicker/images/icon_cal.png', dateFormat: 'yy-mm-dd'});
        });
</script>

</body>
</html>
